package com.iflytek.cosmo.ocr.support.uap;

import java.util.Map;

import com.iflytek.cosmo.ocr.common.config.UapProperties;
import com.iflytek.cosmo.ocr.common.constant.CommonConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * UapPwdStrategy
 * @author admin
 */
@Component
public class UapPwdStrategy {

    /**
     * uapProperties
     */
    @Autowired
    private UapProperties uapProperties;

    /**
     * 密码验证
     * @param pwd
     * @return true/false
     */
    public boolean pwdVerify(String pwd) {
        Map<String, Object> pwdStrategy = uapProperties.getPwdStrategy();
        String reg = pwdStrategy.get("reg").toString();
        return pwd.matches(reg);
    }

    /**
     * 根据密码策略返回错误提示信息
     * @return 提示信息
     */
    public String getPwdErrorMessage() {
        Map<String, Object> pwdStrategy = uapProperties.getPwdStrategy();
        return pwdStrategy.get("errorMsg").toString();
    }

    /**
     * 获取登录错误信息
     * @param errorCode 登录返回错误码
     * @return 错误信息
     */
    public String getLoginErrorMessage(String errorCode) {
        switch (errorCode){
            case CommonConstant.ACCOUNTNOTFOUNDEXCEPTION:
                return CommonConstant.ACCOUNT_NOT_FOUND_EXCEPTION;
            case CommonConstant.INVALIDPASSWORDEXCEPTION:
                return CommonConstant.INVALID_PASSWORD_EXCEPTION;
            case CommonConstant.DISABLEDACCOUNTEXCEPTION:
                return CommonConstant.DISABLED_ACCOUNT_EXCEPTION;
        }
        return null;
    }
}
